// TOWN SCRIPT
//    Town 13: Philippi Sewers

// This is the special encounter script for this town.
// The states INIT_STATE, EXIT_STATE, and START_STATE have
// meanings that are described in the documentation. States you write
// yourself should be numbered from 10-100.

// flags:
// 13, 0 = entry message flag
// 13, 1 = got key
// 13, 2 = opened chest
// 13, 3 = storeroom A message flag
// 13, 4 = storeroom B message flag

begintownscript;

variables;

short choice, x, y;

body;

beginstate INIT_STATE;
	turn_off_training(TRUE);
	set_crime_tolerance(10);
break;

beginstate EXIT_STATE;
break;

beginstate START_STATE;
	if (get_flag(13, 0) == FALSE) {
		set_flag(13, 0, TRUE);
		reset_dialog();
		add_dialog_str(0, "The sewers below Philippi are dark and dank.", 0);
		add_dialog_str(1, "A strange smell permeates the place making breathing difficult.", 0);
		add_dialog_str(2, "After a few moments to acclimate yourselves, you start to breathe normally.", 0);
		add_dialog_choice(0, "Ok");
		choice = run_dialog(TRUE);
	}
break;

beginstate 10;
	x = 39;
	y = 10;
	set_state_continue(13);
break;

beginstate 11;
	x = 46;
	y = 30;
	set_state_continue(13);
break;

beginstate 12;
	x = 45;
	y = 56;
	set_state_continue(13);
break;

beginstate 13;
	block_entry(FALSE);
	reset_dialog();
	add_dialog_str(0, "There is a ladder going up to the sewer cover above.", 0);
	add_dialog_choice(0, "Climb up and out");
	add_dialog_choice(1, "Stay here");
	choice = run_dialog(FALSE);
	if (choice == 1) {
		block_entry(TRUE);
		move_to_new_town(5, x, y);
	}
break;

beginstate 14;
	print_str_color("'Bob was here' is scrawled on the wall.", 4);
break;

beginstate 15;
	print_str_color("The sewer cover at the top of the ladder is locked.", 2);
break;

beginstate 16;
	if (get_flag(13, 1) == FALSE) {
		reset_dialog();
		add_dialog_str(0, "A rotting corpse is sitting next to a sleeping pad.", 0);
		add_dialog_str(1, "The body has been here awhile.", 0);
		add_dialog_str(2, "From the lack of food stuffs, it appears whomever it was starved to death.", 0);
		add_dialog_choice(0, "Search body");
		add_dialog_choice(1, "Leave alone");
		choice = run_dialog(FALSE);
		if (choice == 1) {
			set_flag(13, 1, TRUE);
			reset_dialog();
			add_dialog_str(0, "You prod and poke at the body, uncovering the fact that this was a follower of Zanta.", 0);
			add_dialog_str(1, "Inside one pocket, you find a piece of paper with a single letter, 'A'.", 0);
			add_dialog_str(1, "As you continue to search, you notice a small gold key on a chain around the neck.", 0);
			add_dialog_str(2, "You take it, disappointed that you didn't find a piece of the staff.", 0);
			add_dialog_choice(0, "Ok");
			choice = run_dialog(FALSE);
			change_spec_item(10, 1);
		}
	}
	else {
		message_dialog("The Zanta follower corpse yields nothing else.", "");
	}
break;

beginstate 17;
	if (get_flag(51, 5) == FALSE) {
		set_flag(51, 5, TRUE);
		message_dialog("Inside the chest, nestled in some cloth, is a glittering piece of wood-like material",
			"It's a piece of the staff!");
		take_special_item(10);  // no need for key anymore, take it
		change_spec_item(4, 1); // give staff piece
	}
break;

beginstate 18;
	if (get_flag(13, 3) == FALSE) {
		set_flag(13, 3, TRUE);
		reset_dialog();
		add_dialog_str(0, "A small forgotten storeroom lies behind the open gate in the sewer system.", 0);
		add_dialog_str(1, "A small chest lies across the dusty floor against the north wall.", 0);
		add_dialog_str(2, "You can see and feel the powerful magical trap protecting it even from by the gate.", 0);
		add_dialog_str(3, "You do notice a small gold lock that appears to bypass the trap mechanisms on the front of the chest.", 0);
		add_dialog_choice(0, "Ok");
		choice = run_dialog(TRUE);
	}
break;

beginstate 19;
	if (get_flag(13, 4) == FALSE) {
		set_flag(13, 4, TRUE);
		message_dialog("The storeroom is empty and doesn't appear to have been used recently.", "");
	}
break;
